#include "pch.h"
#include "CRandNum.h"
#include <stdlib.h>


IMPLEMENT_SERIAL(CRandNum, CObject, 1)
CRandNum::CRandNum() :
	m_maxNum(50) {
}

void CRandNum::Init(const int maxNum, const int seedVal) {
	if (seedVal == -1) {
		srand((unsigned)time(NULL));
	}
	else {
		srand((unsigned)seedVal);
	}

	if (m_maxNum > 0)
	{
		m_maxNum = maxNum;
	}
}

int CRandNum::GetRandNum() const {
	return (int)rand() % m_maxNum + 1;
}

void CRandNum::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{	// storing code
		ar << m_maxNum;
	}
	else
	{	// loading code
		ar >> m_maxNum;
	}
}
